package com.wangzh.callback;


import java.util.concurrent.TimeUnit;

public class Test {

    public static void main(String[] args) {
        Callback callback = new Callback() {
            @Override
            public void onCallback(String msg) {
                System.out.println(msg+"-----回调成功了");
            }
        };

        Caller caller = new Caller(callback);
        caller.doSomething();
    }


}

class Caller {
    private Callback callback;

    public void doSomething(){
        System.out.println("开始工作");
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("工作完成");

        callback.onCallback("开始回调");
    }

    public Caller(Callback callback) {
        this.callback = callback;
    }
}

interface Callback{
    void onCallback(String msg);
}
